<?php
/* @var $this ShopProductController */
/* @var $model ShopProduct */
/* @var $form CActiveForm */
?>

<div class="form">
    <script src="<?php echo Yii::app()->baseUrl . '/ckeditor/ckeditor.js'; ?>"></script>
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'shop-product-_shopproduct-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // See class documentation of CActiveForm for details on this,
        // you need to use the performAjaxValidation()-method described there.
        'enableAjaxValidation' => false,
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
    ));
    ?>



    <?php echo $form->errorSummary($model); ?>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'shopid'); ?>
    </div>
    <div class="form_right">
         <?php
        $session = new CHttpSession;
        $session->open();
        $userID = $session['user_salesmart'][3];

        $listshop = Shop::model()->findAll('flag in(1,4) and uid=' . $userID);

        $list = CHtml::listData($listshop, 'id', 'shopName');

        echo $form->dropDownList($model, 'shopid', $list, array('prompt' => '----- Chọn gian hang -----',
            'ajax' => array(
                'type' => 'POST', //request type
                'url' => CController::createUrl('manager/dynamicproduct'), //url to call.
                'update' => '#parentID', //selector to update
                'data' => array('id' => 'js:this.value'),
                
               
        )));
        // echo $form->textField($model,'programid'); array( 'onchange' => 'document.location.href = "' . Yii::app()->request->baseUrl . '/them-city/" + this.value')
        ?>
        <?php echo $form->error($model, 'shopid'); ?>
    </div>

    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_name'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'pr_name', array('size' => 50, 'maxlength' => 50, 'required' => 'required')); ?>
        <?php echo $form->error($model, 'pr_name'); ?>
    </div>

    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_url', array('size' => 50, 'maxlength' => 200, 'required' => 'required')); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'pr_url', array('size' => 60, 'maxlength' => 200)); ?>
        <?php echo $form->error($model, 'pr_url'); ?>
    </div>

    <div class="clear"></div>



    <div class="form_left">
        <?php echo $form->labelEx($model, 'position'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'position', array('class' => 'easyui-numberspinner', 'style' => 'width:80px;')); ?>
        <?php echo $form->error($model, 'position'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'discount'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'discount', array('class' => 'easyui-numberspinner', 'style' => 'width:80px;')); ?>
        <?php echo $form->error($model, 'discount'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'asia_name'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'asia_name', array('size' => 60, 'maxlength' => 200, 'required' => 'required')); ?>
        <?php echo $form->error($model, 'asia_name'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'avatar'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->fileField($model, 'avatar', array('size' => 40, 'maxlength' => 50)); ?>
        <?php echo $form->error($model, 'avatar'); ?>
    </div>

    <div class="clear"></div>


    <div class="form_left">
        <?php echo $form->labelEx($model, 'cate_id'); ?>
    </div>
    <div class="form_right">
         <?php
        if (isset($model->shopid)) {
           

            $listsmenu = ShopNavbar::model()->findAll('flag=1 and shopid=' . $model->shopid);
            $listmenu = CHtml::listData($listsmenu, 'id', 'title');
            echo $form->dropDownList($model, 'cate_id', $listmenu, array('id' => 'parentID'));
        } else {
            echo $form->dropDownList($model, 'cate_id', array(), array('id' => 'parentID'));
        }
        ?>

        <?php echo $form->error($model, 'cate_id'); ?>
    </div>


    <div class="clear"></div>


    <div class="form_left">
        <?php echo $form->labelEx($model, 'ctiID'); ?>
    </div>
    <div class="form_right">
        <?php
           
            $session = new CHttpSession;
            $session->open();
    
            $listsmenu = ShopCity::model()->findAll('flag=1 and shopid=' . $session['user_salesmart'][3]);
            $listmenu = CHtml::listData($listsmenu, 'id', 'cityName');
            echo $form->dropDownList($model, 'ctiID', $listmenu);
       
        ?>
        <?php echo $form->error($model, 'ctiID'); ?>
    </div>


    <div class="clear"></div>


    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_description'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textArea($model, 'pr_description', array('size' => 70, 'maxlength' => 400)); ?>
        <?php echo $form->error($model, 'pr_description'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_meta'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textArea($model, 'pr_meta', array('size' => 70, 'maxlength' => 250)); ?>
        <?php echo $form->error($model, 'pr_meta'); ?>
    </div>
  

    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_enddate'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'pr_enddate', array('class' => 'easyui-datebox', 'data-options' => 'formatter:myformatter,parser:myparser')); ?>
        <?php echo $form->error($model, 'pr_enddate'); ?>
    </div>
    <div class="clear"></div>


    <div class="form_left">
        <?php echo $form->labelEx($model, 'flag'); ?>
    </div>
    <div class="form_right">

        <?php echo $form->dropDownList($model, 'flag', array('0' => 'Đang ẩn', '1' => 'Đang hiện')); ?>
    </div>
    <div class="clear"></div>

    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_content'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textArea($model, 'pr_content', array('id' => 'editor1')); ?>

        <?php echo $form->error($model, 'pr_content'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">.</div>
</div>
<div class="form_right">
    <?php echo CHtml::submitButton('Cập nhật'); ?>
</div>

<?php $this->endWidget(); ?>
<script type="text/javascript">
    CKEDITOR.replace('editor1', {
        filebrowserBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder_1/browse.php?type=files',
        filebrowserImageBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder_1/browse.php?type=images',
        filebrowserFlashBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder_1/browse.php?type=flash',
        filebrowserUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder_1/upload.php?type=files',
        filebrowserImageUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder_1/upload.php?type=images',
        filebrowserFlashUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder_1/upload.php?type=flash'
    });
</script>
<script type="text/javascript">
    function myformatter(date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
    }
    function myparser(s) {
        if (!s)
            return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0], 10);
        var m = parseInt(ss[1], 10);
        var d = parseInt(ss[2], 10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
            return new Date(y, m - 1, d);
        } else {
            return new Date();
        }
    }
</script>

</div><!-- form -->